package day04;
//for循环的演示
public class ForDemo {
    public static void main(String[] args) {
        //for循环中的循环变量num的作用域，仅在当前的for中
        int sum=0;
        int i;
        for ( i = 1; i <= 100; ++i) {
            sum+=i;
        }
        System.out.println("sum="+sum);
        /*
        执行过程:
                   sum=0
           i=1     sum=1
           i=2     sum=1+2
           i=3     sum=1+2+3
           ...     .....
           i=99    sum=1+2+3+...+99
           i=100   sum=1+2+3+...+99+100
           i=101   false 退出循环
         */
        /*
        for (int num = 1; num <= 9; num++) {
            System.out.println(num+"*9="+num*9);
        }
        //System.out.println(num);编译错误
        System.out.println("```````````````````");
        for (int num = 1; num <= 9; num += 2) {
            System.out.println(num+"*9="+num*9);
        }
        System.out.println("```````````````````");
        for (int num = 9; num >= 1; --num) {
            System.out.println(num+"*9="+num*9);
        }
        System.out.println("```````````````````");
        for (int times = 0; times < 5; times++) {
            System.out.println("行动是成功的阶梯!");
        }
        System.out.println("继续执行");

         */
    }
}
